<?php

namespace fztadmin\modules\rbac\models\forms;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\db\ActiveQuery;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use common\models\db\AdminPower as AdminPowerModel;

/**
* AdminPower represents the model behind the search form about `common\models\db\AdminPower`.
*/
class AdminPower extends AdminPowerModel
{
    public function attributeLabels()
    {
        $attributeLabels = parent::attributeLabels();
        $attributeLabels = ArrayHelper::merge($attributeLabels, []);
        return $attributeLabels;
    }

    public function rules()
    {
        $rules = parent::rules();
        /*foreach ($rules as $k => $v) {
            if ($v[1] == 'required'){
                $rules[$k][0] = array_diff($rules[$k][0], ['created_at', 'updated_at', 'created_by', 'updated_by']);
            }
        }*/
        $rules = ArrayHelper::merge($rules, [
            ['route', 'checkRouteHas'],
        ]);
        return $rules;
    }

    public function checkRouteHas($attribute, $params)
    {
        $routes = static::getAllRoutes();
        if ($this->type == self::TYPE_FUN) {
            if (!in_array($this->route, $routes)){
                $this->addError($attribute, "没有找到路由");
            }
        }
    }
}
